package org.rooster.dbmanager.datasource;

import org.rooster.schedule.*;
import java.net.UnknownHostException;

import java.io.File;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 7/29/12
 * Time: 12:36 PM
 * To change this template use File | Settings | File Templates.
 */
public interface DataSource {

    /**
     * Get database properties related to database and database connection.This should be overridden for each database type
     *
     */
    void loadProperties();

    /**
     * Insert a record of resource requirements to the database
     * @param resourceRequirement
     * @return 
     * @throws UnknownHostException 
     * @throws SQLException
     */
    int insertResourceRequirement(ResourceRequirement resourceRequirement) throws UnknownHostException, SQLException;

    /**
     * Retrieves all the records containing resource requirements relevant to schedule
     * @return
     * @throws UnknownHostException
     * @throws SQLException  
     */
    Set retrieveResourceRequirementsForSchedule() throws UnknownHostException, SQLException;

    /**
     * Retrieves the records containing resource requirements for a particular Task
     *
     * @param taskId
     * @return
     * @throws UnknownHostException
     * @throws SQLException
     */
    List getTaskRequirement(int taskId) throws UnknownHostException, SQLException;

    /**
     * Retrieves the set of resource assignments in the generated schedule
     * @return
     * @throws UnknownHostException
     * @throws SQLException
     */
    Set getScheduleResourceAllocations() throws UnknownHostException, SQLException;

    /**
     * Inserts a record containing resource assignment in the generated schedule
     * @param resourceAllocation
     * @return
     * @throws UnknownHostException
     * @throws SQLException
     */
    int insertResourceAllocation(ResourceAllocation resourceAllocation) throws UnknownHostException, SQLException;

    /**
     * clear the table containing generated schedule
     * @throws UnknownHostException
     * @throws SQLException
     */
    void clearScheduleTable() throws UnknownHostException, SQLException;

    /**
     * Retrieves a Resource object containing resource details
     * @param resourceID
     * @return
     * @throws UnknownHostException
     * @throws SQLException
     */
    Resource getResourceRecord(int resourceID) throws UnknownHostException, SQLException;

    /**
     * Set the availability of the resource
     * @return
     * @throws UnknownHostException
     * @throws SQLException
     */
    Set getAvailableResources() throws UnknownHostException, SQLException;

    /**
     * Retrieve the number of total available resources
     * @return
     * @throws UnknownHostException
     * @throws SQLException
     */
    int getTotalResourceCount() throws UnknownHostException, SQLException;

    /**
     * Inserts a record containing resource capability for a particular task
     *
     * @param resourceCapability
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int insertResourceCapability(ResourceCapability resourceCapability) throws SQLException, UnknownHostException;

    /**
     * Retrieves the set of records containing resource capabilities
     *
     * @return
     * @throws SQLException
     * @throws UnknownHostException  
     */
    Set<ResourceCapability> getResourceCapabilities() throws SQLException, UnknownHostException;

    /**
     * Inserts a record containing priority given for a particular resource for a particular task
     *
     * @param managerPreference
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int insertManagerPreference(ManagerPreference managerPreference) throws SQLException, UnknownHostException;

    /**
     * Retrieves the set of priorities
     *
     * @return
     * @throws SQLException
     * @throws UnknownHostException  
     */
    Set<ManagerPreference> getManagerPreferencesSet() throws SQLException, UnknownHostException;

    /**
     * Inserts a record containing resource preference
     *
     * @param resourcePreference
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int insertResourcePreferenceRecord(ResourcePreference resourcePreference) throws SQLException, UnknownHostException;

    /**
     * Retrieves all the records containing resource preferences
     *
     * @return
     * @throws SQLException
     * @throws UnknownHostException  
     */
    Set<ResourcePreference> getResourcePreferenceSet() throws SQLException, UnknownHostException;

    /**
     * Retrieves the set of reosurces
     * @return
     * @throws SQLException
     * @throws UnknownHostException  
     */
    Set<Resource> getAllResources() throws SQLException, UnknownHostException;

    /**
     * Set the resource availability
     * @param resourceId
     * @param availability
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int setResourceAvailability(int resourceId, int availability) throws SQLException, UnknownHostException;

    /**
     * Returns the resource having the name containing the given searchString
     * @param searchString
     * @return
     * @throws SQLException
     * @throws UnknownHostException  
     */
    Set<Resource> searchResourcesByName(String searchString) throws SQLException, UnknownHostException;

    /**
     * Retrieve the set of preferences for a particular resource
     * @param resourceId
     * @return
     * @throws SQLException
     * @throws UnknownHostException  
     */
    Set<ResourcePreference> retrievePreferencesForResource(int resourceId) throws SQLException, UnknownHostException;

    /**
     * Update the resource details
     *
     * @param resource
     * @param previousResourceId
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int updateResourceDetails(Resource resource, int previousResourceId) throws SQLException, UnknownHostException;

    /**
     * Save the profile image of the resource
     *
     * @param resourceId
     * @param file
     * @return 
     * @throws SQLException
     * @throws UnknownHostException 
     * @throws FileNotFoundException
     */
    int saveResourceImage(int resourceId, File file) throws SQLException, UnknownHostException, FileNotFoundException;

    /**
     * Updates the resource preference record
     *
     * @param resourcePreference
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int updateResourcePreference(ResourcePreference resourcePreference) throws SQLException, UnknownHostException;

    /**
     * Returns the Task having the given task id
     *
     * @param taskId
     * @return
     * @throws SQLException
     * @throws UnknownHostException
     */
    Task getTaskById(int taskId) throws SQLException, UnknownHostException;

    /**
     * Returns the TimeSlot object having the given id
     *
     * @param id
     * @return
     * @throws SQLException
     * @throws UnknownHostException
     */
    TimeSlot getTimeSlotById(int id) throws SQLException, UnknownHostException;

    /**
     * Update resource capability of a particular resource
     * @param resourceCapability
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int updateResourceCapability(ResourceCapability resourceCapability) throws SQLException, UnknownHostException;

    /**
     * Update the priority record containing the particular priority
     *
     * @param managerPreference
     * @return 
     * @throws SQLException
     * @throws UnknownHostException  
     */
    int updateManagerPreference(ManagerPreference managerPreference) throws SQLException, UnknownHostException;

    /**
     * 
     * @return Set
     * @throws SQLException
     * @throws UnknownHostException
     */
    Set<ResourceType> getResourceTypes() throws SQLException, UnknownHostException;

    /**
     * 
     * @return
     * @throws SQLException
     * @throws UnknownHostException
     */
    Set<Resource> getResourcesByResourceType(int resourceTypeId) throws SQLException, UnknownHostException;
}
